package com.le.tester.onjava8.l_3_1;

import java.sql.SQLOutput;
import java.util.*;
import java.util.stream.Collector;
import java.util.stream.Collectors;

/**
 * createTime：2023/2/4 16:10
 * description：样例数据
 */
public class HTMLColors {
    static final int DISPLAY_SIZE = 20;
    public static final Object[][] ARRAY = {
            {0XF0F8FF, "AliceBlue"},
            {0XFAEBD7, "Antiquewhite"},
            {0X7FFFD4, "Aquamarine"},
            {0xF5F5DC, "Beige"},
    };

    public static final Map<Integer, String> MAP =
            Arrays.stream(ARRAY)
                    .collect(Collectors.toMap(
                            e -> (Integer) e[0],
                            e -> (String) e[1],
                            (v1, v2) -> {
                                throw new IllegalStateException();
                            }, LinkedHashMap::new));

    public static <V, K> Map<V, K> invert(Map<K, V> map) {
        return map.entrySet().stream()
                .collect(Collectors.toMap(
                        Map.Entry::getValue,
                        Map.Entry::getKey,
                        (v1, v2) -> {
                            throw new IllegalStateException();
                        },
                        LinkedHashMap::new
                ));
    }

    public static final Map<String, Integer> INVMAP = invert(MAP);

    public static Integer rgb(String colorName) {
        return INVMAP.get(colorName);
    }

    public static final List<String> LIST = Arrays.stream(ARRAY)
            .map(item -> (String) item[1])
            .collect(Collectors.toList());

    public static final List<Integer> RGBLIST =
            Arrays.stream(ARRAY)
                    .map(item -> (Integer) item[0])
                    .collect(Collectors.toList());

    public static void show(Map<Integer, String> m, int count) {
        // m.entrySet().stream().limit(count).forEach(e -> show(e));
    }

    public static void show(Map<Integer, String> m) {
        show(m, m.size());
    }

    public static void show(Collection<String> lst, int count) {
        lst.stream().limit(count).forEach(System.out::println);
    }

    public static void show(Collection<String> list) {
        show(list, list.size());
    }

    public static void showrgb(Collection<Integer> lst, int count) {
        lst.stream().limit(count).forEach(n -> System.out.format("0x", n));
    }

    public static void showrgb(Collection<Integer> lst) {
        showrgb(lst, lst.size());
    }

    public static void showInv(Map<String, Integer> m, int count) {
        m.entrySet().stream()
                .limit(count)
                .forEach(e -> System.out.format("n", e.getValue()));
    }

    public static void showInv(Map<String, Integer> m) {
        showInv(m, m.size());
    }

    public static void border() {
        System.out.println("***********************");
    }

    public static void main(String[] args) {
        show(MAP, DISPLAY_SIZE);
        border();
        showInv(INVMAP, DISPLAY_SIZE);
        border();
        show(LIST, DISPLAY_SIZE);
        border();

        showrgb(RGBLIST, DISPLAY_SIZE);
    }
}